package com.eduction.service.impl;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.eduction.modules.system.dao.SchoolItemDataDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eduction.modules.system.dao.SchoolItemDataRepository;
import com.eduction.modules.system.entity.SchoolItemData;
import com.eduction.service.SchoolItemDataService;

@Service
public class SchoolItemDataServiceImpl implements SchoolItemDataService {

	@Autowired
	private SchoolItemDataRepository schoolItemDataRepository;

	@Autowired
	private SchoolItemDataDao schoolItemDataDao;
	
	@Override
	public SchoolItemData querySchoolItemData(String schoolId, String itemId,int year) throws SQLException {
		SchoolItemData sd = schoolItemDataRepository.querySchoolItemData(schoolId, itemId,year);
		return sd;
	}

	@Override
	public void saveSchoolItemData(SchoolItemData s) {
		schoolItemDataRepository.saveSchoolItemData(s);
		
	}

	@Override
	public List<SchoolItemData> querySchoolItemDataBySchoolId(String itemId,String schoolId) throws SQLException{
		List<SchoolItemData> sdList = schoolItemDataRepository.querySchoolItemDataBySchoolId(itemId,schoolId);
		return sdList;
	}

	@Override
	public SchoolItemData queryById(String p_id){
		return schoolItemDataDao.findOne(p_id);
	}

	@Override
	public void updateSchoolItemData(SchoolItemData s) throws SQLException {
		// TODO Auto-generated method stub
		schoolItemDataRepository.updateSchoolItemData(s);
	}

	@Override
	public List<SchoolItemData> querySchoolItemDataByItemIdAndSchoolId(String itemId, String schoolId,String year) throws SQLException {
		if(year==null){

			Calendar cal = Calendar.getInstance();
			Date dt = new Date();
				cal.setTime(dt);
			year = String.valueOf(cal.get(Calendar.YEAR));
		}
		List<SchoolItemData> sdList = schoolItemDataRepository.querySchoolItemDataByItemIdAndSchoolId(itemId,schoolId,year);
		return sdList;
	}

}
